const router = require('koa-router')();
const fs = require('fs');
const qr = require('qr-image');

//上传图片
router.all('/qr', async (ctx) => {
  try {
    // 大小默认5，二维码周围间距默认1
    const img = qr.image(ctx.query.text, {
      type: 'png',
      size: 5,
      margin: 1
    });
    ctx.status = 200;
    ctx.type = 'image/png';
    ctx.body = img;
  } catch (e) {
    ctx.status = 414;
    ctx.set('Content-Type', 'text/html');
    ctx.body = '<h1>414 Request-URI Too Large</h1>';
  }
})
module.exports = router.routes();
